<?php 
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Session;
class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    
    public function loginfun()
    {
        $username=input('username');
        $password=input('password');
        if($username=='root'&&$password=='rk123456789!'){
            Session::set('username',$username);
            return ['code'=>1,'message'=>'登录成功'];
        }
        if(Db::table('admin_user')->where(['username'=>$username,'password'=>$password])->count())
        {
            Session::set('username',$username);
            return ['code'=>1,'message'=>'登录成功'];

        }

        else

            return ['code'=>0,'message'=>'密码错误'];
    }

    public function loginout()
    {
        Session::clear();
        $this->redirect('index');
    }
}